import Vue from 'vue';
import Router from 'vue-router';
import routes from './routes';
import store from '../store';
import * as MutationTypes from '../store/root/mutation-types';

Vue.use(Router);

const router = new Router({
  routes
});

router.beforeEach(function (to, from, next) {
  // 页面缓存
  const { name, meta = {} } = to;
  const { keepAlive = false } = meta;
  if (keepAlive) {
    store.commit(MutationTypes.ADD_INCLUDE, name);
  }

  next();
});

export default router;
